﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Threading;
using Telerik.WinControls;
using Telerik.WinControls.UI;
namespace Bitis_KeToanThue_Pro_DanhMuc.Common
{
   public static class ShowFormMenuDanhMucProject
    {
       public static void MdiShowForm(string Fullname, string formname, RadPageView radpadgeview1, Image hinh)
       {

           RadForm t = layformbyproject(Fullname);
           t.TopLevel = false;
           t.Dock = DockStyle.Fill;
           t.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

           foreach (RadPageViewPage paget in radpadgeview1.Pages)
           {
               if (paget.Text == t.Text)
               {
                   return;
               }

           }


           RadPageViewPage page = new RadPageViewPage();
           t.Parent = page;
           page.Text = t.Text;
           page.Image = hinh;
           page.Controls.Add(t);

           radpadgeview1.Pages.Add(page);
           t.Show();
           radpadgeview1.SelectedPage = page;


       }
        public static void openformcloseformfinal(string fullname, string formname, RadForm f)
        {

            Thread t = new Thread(new ThreadStart(
              delegate()
              {
                  ThreadProc(fullname, formname);
              }


              ));
            t.SetApartmentState(ApartmentState.STA);
            t.Start();

            f.Close();
        }
        public static RadForm layformbyproject(string Fullname)
        {
            //project.folder.formname
            /* Get its type */
            Type t = Type.GetType(Fullname, false, true);

            /* Get Object of Form By its Fullname */
            object Obj_Form = Activator.CreateInstance(t);

            /* Cast the Object to Desire Type and Show it  */
            return Obj_Form as RadForm;


        }
        public static void ThreadProc(string Fullname, string formname)
        {
            RadForm t = layformbyproject(Fullname);

            bool check = false;
            foreach (RadForm f in Application.OpenForms)
            {
                if (f.Name == formname)
                {
                    check = true;
                }
            }
            if (check == true)
            {
                t.Focus();
                check = false;
            }
            else
            {
                Application.Run(t);
            }

        }

        public static void showformbymenuloaddulieudatabase(string formname, string Fullname, int command)
        {
            Type t = Type.GetType(Fullname, false, true);
            object Obj_Form = Activator.CreateInstance(t);
            foreach (RadForm f in Application.OpenForms)
            {
                if (f.Name == formname)
                {
                    f.Focus();
                    return;
                }
            }
            if (command == 1)
            {
                (Obj_Form as RadForm).Show();
            }
            else
            {
                (Obj_Form as RadForm).ShowDialog();
            }
        }
    }
}
